<template>
  <div>
    <imp-info :fields="fields" @toSubmit="toSubmit"/>
  </div>
</template>

<script>
import impInfo from '@/components/impInfo'
import api from '@/api'
export default {
  name: 'student-imp-info',
  data () {
    return {
      fields: [
        {label: '姓名(真实姓名)', key: 'name', type: 'input'},
        {label: '生日', key: 'birthday', type: 'date'}
      ]
    }
  },
  methods: {
    toSubmit (params) {
      let user = JSON.parse(window.sessionStorage.getItem('user'))
      let formData = new FormData()
      formData.append('id', user.id)
      formData.append('name', params.name)
      if (params.head_sculpture) {
        formData.append('head_sculpture', params.head_sculpture)
      }
      formData.append('birthday', new Date(params.birthday).valueOf().toString())
      api.perfectInfo({
        params: formData,
        callback: res => {
          if (res.data.error_code === 0) {
            this.$toast.success({
              message: res.data.message,
              duration: 1000,
              forbidClick: true,
              onClose: () => {
                this.$router.push('/myIndex')
              }
            })
          }
        }
      })
    }
  },
  components: {
    impInfo
  },
  created () {
  }
}
</script>

<style scoped>

</style>
